package designpatterns.responsibility.chain.code.log;

/**
 * 每个日志有自己的级别 info,err,debug,warn
 * 给出日志，请打印出日志的级别
 *
 */
public class Client {
    public static void main(String[] args) {
        AbstractLoggerChain chain = getLoggerChain();

        Log info = new Log(AbstractLoggerChain.INFO,"this is info level log!");
        Log err = new Log(AbstractLoggerChain.ERR,"this is err level log!");
        Log debug = new Log(AbstractLoggerChain.DEBUG,"this is debug level log!");

        chain.doPrint(info);
        chain.doPrint(err);
        chain.doPrint(debug);
        chain.doPrint(new Log("no","其他日志级别"));

    }

    private static AbstractLoggerChain getLoggerChain() {
        AbstractLoggerChain infoLevel = new InfoLevel(AbstractLoggerChain.INFO);
        AbstractLoggerChain errLevel = new ErrLevel(AbstractLoggerChain.ERR);
        AbstractLoggerChain debugLevel = new DebugLevel(AbstractLoggerChain.DEBUG);
        AbstractLoggerChain warnLevel = new WarnLevel(AbstractLoggerChain.WARN);

        // 建立链关系
        infoLevel.setNextLevel(errLevel);
        errLevel.setNextLevel(debugLevel);
        debugLevel.setNextLevel(warnLevel);

        return infoLevel;
    }


}
